package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Actual_Form_JiXie_GuanTiYou extends BaseActivity {

	private PictureButton PictureButton_tiyou;
	private EditText editText_tiyouzhongliang, editText_jinyoudanjia,editText_shijizhongliang,editText_midu,editText_shengshu;

	@Override
	public void onClick(View view) {
		super.onClick(view);
	}
	@Override
	protected void onResume() {
		PictureButton_tiyou.postInvalidate();
		super.onResume();
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actual_form_jixie_guantiyou);
		InitControls();
	}

	@Override
	protected void SaveJsonData() {
		try {
			IsJson1 = true; mFinished = 1 ;
			JsonMyID();
			getTask();
			getChangKuanGao();
			
			getGPS();
			getCurrentUser();		
			getMemo();
			JsonPicture();
			JsonPicture_Ext();
		}catch (Exception e) {
		}
	}
	
	protected void getChangKuanGao() throws JSONException {
		if (editText_tiyouzhongliang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_tiyou_tiyouzhongliang), editText_tiyouzhongliang.getText().toString());
		}
		if (editText_jinyoudanjia!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_tiyou_jinyoudanjia), editText_jinyoudanjia.getText().toString());
		}
		if (editText_shijizhongliang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_tiyou_shijizhongliang), editText_shijizhongliang.getText().toString());
		}
		if (editText_midu!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_tiyou_midu), editText_midu.getText().toString());
		}			
		if (editText_shengshu!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_tiyou_shengshu), editText_shengshu.getText().toString());
		}		
	}

	protected void JsonPicture_Ext() throws JSONException {
		if (PictureButton_tiyou!=null) {
			mJson.put( PictureButton_tiyou.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_tiyou.mFileName);
		}
	}	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_tiyou, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	@Override
	public void Back() {
		super.Back();
	}

	@Override
	public void InitControls() {
		super.InitControls();
		PictureButton_tiyou = (PictureButton) findViewById(R.id.PictureButton_tiyou);

		editText_tiyouzhongliang = (EditText) findViewById(R.id.editText_tiyouzhongliang);
		editText_jinyoudanjia = (EditText) findViewById(R.id.editText_jinyoudanjia);
		editText_shijizhongliang = (EditText) findViewById(R.id.editText_shijizhongliang);
		editText_midu = (EditText) findViewById(R.id.editText_midu);
		editText_shengshu  = (EditText) findViewById(R.id.editText_shengshu);
	}
	
	@Override
	public Boolean IsPassed() {
		if (super.IsPassed()) {
			if(!CheckEditNumber(editText_tiyouzhongliang))
				return false;
			if(!CheckEditNumber(editText_jinyoudanjia))
				return false;			
			if(!CheckEditNumber(editText_shijizhongliang))
				return false;
			if(!CheckEditNumber(editText_midu))
				return false;
			if(!CheckEditNumber(editText_shengshu))
				return false;
			if (!PictureButton_tiyou.IsExist()) {
				Utility.MessageBox( this,PictureButton_tiyou.FIELD );
				return false;
			}
			return true;
		}else {
			return false;
		}
	}

}
